<%@page import="java.net.URLEncoder"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="boardVo" class="Board.BoardVo" />
<jsp:setProperty property="*" name="boardVo" />
	<%
		 /*  String uploadPath = ""; //경로 저장 String
	
		String realPath = boardVo.getRequest().getServletContext()
		.getRealPath("WebContent");
		String path = realPath.replace("\\WebContent", "");
		String pro = path.substring(path.lastIndexOf("\\") + 1, path.length());
		uploadPath = realPath.substring(0, realPath.indexOf(".")) + pro
	+ "\\WebContent\\homepage\\board\\boardData\\";  */
		
		String realPath = boardVo.getRequest().getServletContext()
				.getRealPath("WebContent");
		String path = realPath.replace("\\WebContent", "");
		String pro = path.substring(path.lastIndexOf("\\") + 1, path.length());
		path = realPath.substring(0, realPath.indexOf(".")) + pro
				+ "\\WebContent\\homepage\\board\\BoardData\\";
		String savePath = "C:\\Users\\jhta\\Documents\\workspace\\svn_Clamp\\WebContent\\homepage\\board\\boardData\\";
		/* String savePath = "C:\\Users\\jhta\\Desktop\\eclipse-jee-kepler-SR2-win32\\workspace\\svn_samjo_pro\\WebContent\\upload"; */
		ServletContext content = this.getServletContext();
		String sFilePath = savePath+"/"+boardVo.getBo_file();
		//파일을 읽기 위한 버퍼정의
		byte b[] = new byte[4096];
		File file = new File(sFilePath);
		FileInputStream in = new FileInputStream(sFilePath);
		
		//클라이언트의 요청에 따른 응답정보 셋팅
		String mineType = getServletContext().getMimeType(sFilePath);
		if(mineType == null) mineType = "application/octect-stream";
		response.setContentType(mineType);
		
		//한글 파일명 처리
		//String encoding = new String(bv.getFilename().getBytes("utf-8"),"8859_1");
		String encoding="";
		if((request.getHeader("User-Agent").indexOf("Firefox"))>-1){
			String temp = boardVo.getBo_file().replace(" ", "");
			encoding = new String(temp.getBytes("utf-8"),"8859_1");
		}else{//IE,크롬,오페라
			encoding =  URLEncoder.encode(boardVo.getBo_file(), "UTF-8"); 
			encoding = encoding.replace("+", "%20");
		}
		//다운로드 다이알로그창 표시
		response.setHeader("Content-Disposition", "attachment;filename="+encoding);
	
		//getOutputStream() 오류 방지(더블클릭시도 예방)
		out.clear();
		out=pageContext.pushBody();
		
		//지정된 경로에 파일 저장
		ServletOutputStream sos = response.getOutputStream();
		int read=0;
		while((read=in.read(b,0,b.length))!=-1){
			sos.write(b,0,read);
		}
		sos.flush();
		sos.close();
		in.close();
	%>
</body>
</html>